import os
import random
import shutil
from pathlib import Path

import pytest


@pytest.fixture
def kv_path():
    path = Path('testdata.kv.bin')
    if path.exists():
        if path.is_dir():
            shutil.rmtree(path)
        else:
            path.unlink()
    yield path
    if path.exists():
        if path.is_dir():
            shutil.rmtree(path)
        else:
            path.unlink()


@pytest.fixture
def insert_keys():
    keys = set()
    while len(keys) < 10_0000:
        keys.add(os.urandom(16))
    return list(keys)


@pytest.fixture
def get_keys(insert_keys):
    keys = set()
    random.sample(insert_keys, 5_0000)
    while len(keys) < 10_0000:
        keys.add(os.urandom(16))
    return list(keys)
